package com.example.sport.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.sport.domain.College;
import com.example.sport.domain.Event;
import com.example.sport.domain.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CollegeMapper extends BaseMapper<College> {


    @Select({
            "SELECT c.name AS name,",
            "c.leader AS leader,",
            "c.id AS id,",
            "cr.total_points AS totalPoints,",
            "cr.total_rank AS totalRank",
            "FROM t_college c",
            "JOIN t_user u ON c.id = u.college_id",
            "JOIN college_ranking cr ON c.id = cr.college_id",
            "WHERE u.id = #{userId}"})
    College getCollegeInfoByUserId(String userId);

    @Select({
            "SELECT c.name AS name,",
            "c.leader AS leader,",
            "c.id AS id,",
            "cr.total_points AS totalPoints,",
            "cr.total_rank AS totalRank",
            "FROM t_college c",
            "JOIN college_ranking cr ON c.id = cr.college_id",
            "WHERE c.name like CONCAT('%', #{name}, '%')"})
    List<College> selectListByName(String name);

    @Select({
            "SELECT c.name AS name,",
            "c.leader AS leader,",
            "c.id AS id,",
            "cr.total_points AS totalPoints,",
            "cr.total_rank AS totalRank",
            "FROM t_college c",
            "JOIN college_ranking cr ON c.id = cr.college_id",
            "WHERE c.id = #{name} "})
    College selectListById(String id);
}
